
#include "skill.h"
#include "player.h"
#include "monster.h"


Skill::Skill(Player* _player, const int& cd, const double& scA, const double& scD, const double& scS, const double& scL, const double& scDI) :
    playerChar(_player), cooldown(cd), currentCooldown(0), scAttack(scA), scDefense(scD), scSpeed(scS), scLevel(scL), scDefIgnore(scDI), selfBuff(0)
{
    //null;
}

Skill::~Skill()
{
    if (selfBuff)
    {
        delete selfBuff;
    }
}

void Skill::makeBuff(const int& dur, const std::string& cancelID)
{
    selfBuff = new Buff(dur, cancelID);
}

void Skill::setBuff(Bufftype btype, const int& strength)
{
    selfBuff->set(btype, strength);
}

double Skill::getDamage() const
{
    // calculates damage for the skill
    double x = (playerChar->getAttack() * scAttack) + (playerChar->getDefense() * scDefense) + (playerChar->getSpeed() * scSpeed) + (playerChar->getLevel() * scLevel) - (playerChar->getEnemy()->getDefense() * (1 - scDefIgnore));
    return x;
}

void Skill::activate()
{
    // activates cooldown, applies buff
    currentCooldown = cooldown;
    if (selfBuff)
    {
        playerChar->addBuff(*selfBuff);
    }
}

void Skill::tick()
{
    // reduces cooldown if needed, the ability can be used when currentCooldown == 0
    if (currentCooldown > 0)
    {
        --currentCooldown;
    }
}
